package com.netty.demo.binary.factorial;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;

/**
 * @author shengtao
 * @Description:
 * @date 2018/09/12 13:55
 */
public class FactorialClient {
    static final int COUNT = 1000;
    static final int PORT = 5001;
    static final int SIZE = 256;
    static final String HOST = "127.0.0.1";
    public static void main(String[] args) throws Exception {
        EventLoopGroup group = new NioEventLoopGroup();
        try {
            Bootstrap b = new Bootstrap();
            b.group(group)
                    .channel(NioSocketChannel.class)
                    .handler(new FactorialClientInitializer());
            ChannelFuture f = b.connect(HOST, PORT).sync();
            FactorialClientHandler handler = (FactorialClientHandler) f.channel().pipeline().last();

            System.err.format("Factorial of %,d is: %,d", 1, handler.getFactorial());
        } finally {
            group.shutdownGracefully();
        }
    }
}
